<script setup>
import { ref } from 'vue'

// 定义props
const props = defineProps({
  name: {
    type: [String, Number],
    required: true
  },
  title: {
    type: String,
    required: true
  },
  disabled: {
    type: Boolean,
    default: false
  },
  change: {
    type: Boolean,
    default: true
  }
})

// 展开状态
const isActive = ref(false)

// 切换展开状态
const toggleAccordion = () => {
  if (!props.disabled) {
    isActive.value = !isActive.value
  }
}
</script>

<template>
  <div class="accordion">
    <div
        class="accordion-header"
        :class="{ disabled: disabled }"
        @click="toggleAccordion"
    >
      <div class="accordion-title">{{ title }}</div>
      <div class="accordion-icon" :class="{ active: isActive }">▼</div>
    </div>

    <transition name="accordion">
      <div v-show="isActive" class="accordion-content">
        <slot></slot>
      </div>
    </transition>
  </div>
</template>

<style scoped>
.accordion {
  border: 1px solid #ddd;
  border-radius: 4px;
  margin-bottom: 10px;
}

.accordion-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 15px;
  background-color: #f5f5f5;
  cursor: pointer;
}

.accordion-header.disabled {
  cursor: not-allowed;
  opacity: 0.6;
}

.accordion-title {
  font-weight: bold;
}

.accordion-icon {
  transition: transform 0.3s ease;
}

.accordion-icon.active {
  transform: rotate(180deg);
}

.accordion-content {
  padding: 15px;
  background-color: #fff;
}

.accordion-enter-active,
.accordion-leave-active {
  transition: all 0.3s ease;
}

.accordion-enter-from,
.accordion-leave-to {
  opacity: 0;
  transform: translateY(-10px);
}
</style>